#include "stdafx.h"
#include "MiniCppUnit.hxx"
#include "leudgrid/EventQueueThread.h"
#include "leudgrid/eventbase.h"
class myEQ : public LEUD::EventQueueThread
{
public:
	virtual int OnStart(){return 0;}
	virtual int OnStop(){return 0;}
};
volatile LONG procesed_num = 0;
class myE : public LEUD::EventBase
{
public:
	virtual void OnHanding(unsigned int queue_id,void* param)
	{
		::InterlockedIncrement(&procesed_num);
		delete this;
	}
};
class TestEventQueueThread : public TestFixture<TestEventQueueThread>
{
public:
	TEST_FIXTURE( TestEventQueueThread )
	{
		TEST_CASE( testAssert );
		TEST_CASE( testAssertMessage );
		TEST_CASE( testAdditionInts );
		TEST_CASE( testEventQueueThread );
	}
	void testAssert()
	{
		ASSERT(3==1+2);
	}
	void testAssertMessage()
	{
		ASSERT_MESSAGE( 2==1+1, "2 should be 1 plus 1 ");
	}
	void testAdditionInts()
	{
		ASSERT_EQUALS( 2, 1+1 );
	}
	void testEventQueueThread()
	{
		myEQ eq;
		eq.Start(0,0);
		for(int i = 0;i < 10000;i++ )
		{
			eq.PushEvent(new myE);
		}
		Sleep(1000);
		eq.Stop();
		ASSERT(procesed_num > 0 );
	}
};

REGISTER_FIXTURE( TestEventQueueThread );
